import 'package:flutter/material.dart';

void main() {
  runApp(MainPage());
}
class MainPage extends StatefulWidget {
  MainPage({Key? key}) : super(key: key);

  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  final ScrollController _controller = ScrollController();//滚动控制器
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
       home:Scaffold(appBar:AppBar(title:Text("滚动列表"),) ,
       body:Stack(
        children: [
          SingleChildScrollView(
            controller: _controller,
            padding: EdgeInsets.all(20),
            child: Column(
            children:List.generate(100, (index){
              return Container(
                margin: EdgeInsets.all(10),
                width: double.infinity,
                color: Colors.pink,
                height: 100,
                child:Text("我是第${index+1}个容器",style: TextStyle(color: Colors.white,fontSize: 20,)),
                alignment: Alignment.center,
              );
            }),
       ),
       ),
       Positioned(
        right: 20,
        top: 20,
        child: GestureDetector(
          onTap: (){
            _controller.animateTo(_controller.position.maxScrollExtent, duration: Duration(seconds: 1), curve: Curves.ease);
            print("点击了向下箭头");
          },
          child:Container(
          decoration: BoxDecoration(
            color: Colors.grey,
            borderRadius: BorderRadius.circular(40),
          ),
          padding: EdgeInsets.all(10),
          child: Icon(Icons.arrow_circle_down,color: Colors.white,),
        ),
        )
       ),
       Positioned(
        right: 20,
        bottom: 20,
        child: GestureDetector(
          onTap: (){
            _controller.animateTo(0, duration: Duration(seconds: 1), curve: Curves.ease);
            print("点击了向上箭头");
          },
          child:Container(
          decoration: BoxDecoration(
            color: Colors.grey,
            borderRadius: BorderRadius.circular(40),
          ),
          padding: EdgeInsets.all(10),
          child: Icon(Icons.arrow_circle_up,color: Colors.white,),
        )
          )
          
       )
        ]
    )));  
  }
}